package com.plugin.manage.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.plugin.manage.pojo.dto.ElderBookingInfoDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 老人预订床位信息Mapper
 * 
 * @author mark
 * @date 2025-08-01
 */
@Mapper
public interface ElderBookingMapper {

    /**
     * 三表联查获取老人预订床位信息（分页）
     * elder_info, elder_check_in, elder_consultation 三表联查
     */
    @Select("SELECT " +
            "ei.realname AS realName, " +
            "ec.consultant_name AS consultantName, " +
            "ec.consultant_phone AS consultantPhone, " +
            "eci.room_number AS roomNumber, " +
            "eci.remark AS remark, " +
            "eci.check_in_date AS checkInDate, " +
            "ec.expected_check_in_date AS expectedCheckInDate, " +
            "eci.check_in_amount AS checkInAmount, " +
            "eci.deposit_amount AS depositAmount, " +
            "eci.status AS status, " +
            "ei.elder_id AS elderId, " +
            "ec.id AS consultationId, " +
            "eci.id AS checkInId " +
            "FROM elder_info ei " +
            "INNER JOIN elder_check_in eci ON ei.elder_id = eci.elder_id " +
            "INNER JOIN elder_consultation ec ON ei.elder_id = ec.elder_id AND eci.contact_id = ec.id " +
            "WHERE ei.del = 0 AND ec.del = 0 AND eci.is_leave = 0 " +
            "ORDER BY eci.check_in_date DESC")
    IPage<ElderBookingInfoDTO> getElderBookingInfo(IPage<ElderBookingInfoDTO> page);

}
